<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul {
      width: 300px;
    }

    ul li {
      height: 50px;
      border-bottom: 1px solid black;
    }
  </style>
</head>

<body>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
  </ul>
  <script>
    const list = document.querySelectorAll('ul li')
    function enter() {
      this.style.background = 'red'
    }
    function leave() {
      this.style.background = ''
    }
    list.forEach(item => {
      item.onmouseenter = lodashEnter(enter, 100)
      item.onmouseleave = leave
    })
    // 节流 多次执行先执行第一次 后面只要时间没到预定时间就不会执行函数
    function lodashEnter(fn, time) {
      let initTime = 0
      return function () {
        // 获得当前的时间
        const nowTime = Date.now()
        if (nowTime - initTime < time) {
          return
        }
        initTime = nowTime
        // 修改this指向
        console.log(this);
        fn.call(this)
      }
    }
  </script>
</body>

</html>